${r'<%@'} page language="java" pageEncoding="UTF-8" ${r'%>'}
${r'<%@'} include file="/view/common/include.jsp" ${r'%>'}
<title>${table.remarks}</title>

<script type="text/javascript">
	var grid = null;
	var form = null;

	$(function() {

		initGrid();

	});

	function initGrid() {
		grid = $('#maingrid').datagrid(
				{
					height : bodyHeight(),
					url : CP + '${actionVisitLocation}/listWithPage.htm',
					method : 'POST',
					queryParams : {},
					idField : '${table.pks[0].column_name}',
					striped : true,
					fitColumns : true,
					singleSelect : false,
					rownumbers : true,
					pagination : true,
					nowrap : false,
					// 	pageSize : 20,
					// 	pageList : [ 10, 20, 50, 100, 150, 200 ],
					showFooter : true,
					columns : [ [ 
								  { field : 'ck', checkbox : true }, 					
							<#list columns as column>
								<#assign hide="false">
								<#assign width="width(0.2)">
								<#if column.isPk == true>
									<#assign hide="true">
									<#assign width="1">
								</#if>
								<#if column_has_next>
					              { field : '${column.column_name}', title : '${column.remarks}', align : 'center', hidden:${hide}, width : ${width} }, 								
								<#else>
								  { field : '${column.column_name}', title : '${column.remarks}', align : 'center', hidden:${hide}, width : ${width} }
								</#if>	
							</#list>							   
					              ] ],
					toolbar:${r'${'}BUTTON_SOURCE[param.menuId]["default"]==null?[]:BUTTON_SOURCE[param.menuId]['default']},
					onBeforeLoad : function(param) {
					},
					onLoadSuccess : function(data) {

					},
					onLoadError : function() {

					},
					onClickCell : function(rowIndex, field, value) {

					}
				});
	}

	/*grid click事件*/
	function itemclick(item) {
		switch (item) {
		case 1:
			// 新增
			createWindow("新增", CP + "${actionVisitLocation}/add.htm?r="+ Math.random()+'&optName=add', 730, 400, true, true, null);
			break;
		case 2:
			// 修改
			var rows = grid.datagrid("getSelections");
			if (rows.length > 1 || rows.length == 0) {
				$.messager.alert("提示", '请仅且选择一条记录进行修改！', 'warning');
			} else {
				createWindow("修改", 
							CP+ "${actionVisitLocation}/search.htm?id="+ rows[0].${table.pks[0].column_name} + "&r=" + Math.random()+'&optName=edit', 
							730, 400,true, true, null);
			}
			break;
		case 3:
			// 删除
			var rows = grid.datagrid("getSelections");
			if (rows && rows.length > 0) {
				$.messager.confirm("确认删除选中的记录吗？", "温馨提示", function(yes) {
					if (yes) {
						var ids = "";
						for (var i = 0; i < rows.length; i++) {
							if(ids == ""){
								ids = rows[i].${table.pks[0].column_name};
							}else{
								ids = ids +","+ rows[i].${table.pks[0].column_name};
							}
						}
						
						$.ajax({
							type : "POST",
							url : CP + '${actionVisitLocation}/delete.htm?r='+ Math.random(),
							dataType : 'json',
							data:{
								"id":ids
							},							
							success : function(msg) {
								if (msg.flag) {
									refreshGrid();
								} else {
									$.messager.alert("提示", msg.desc, 'error');
								}
							}
						});
					}
				});
			} else {
				$.messager.alert("提示", '请至少选择一条记录进行删除操作！', 'warning');
			}
			break;
		case 4:
			// 查看
			var rows = grid.datagrid("getSelections");
			if (rows.length > 1 || rows.length == 0) {
				$.messager.alert("提示", '请至多选择一条记录进行查看！', 'warning');
			} else {
				createWindow("查看", CP
						+ "${actionVisitLocation}/search.htm?id=" + rows[0].${table.pks[0].column_name} + "&r=" + Math.random()+'&optName=search', 730, 400,
						true, true, null);
			}
			break;
		default:
			break;
		}
	}

	/*公用方法*/
	function searchGrid() {
		refreshGrid();
	}

	function clearSearchForm() {
		clearForm();
		refreshGrid();
	}

	/*其他方法*/
</script>

</head>
<body style="padding: 1px 0px 0px 0px;">

	<!-- 搜索区域 -->
	<div id="queryArea" title="queryArea" style="width: 100%;">
		<form id="dataForm">
			<div class="l-form">
				<div class="l-form-container">
					<ul>
				<#list columns as column>
					<#if column.isPk != true>
						<li class="l-fieldcontainer">
							<ul>
								<li class="li_label"><label>${column.remarks} </label></li>
								<li class="li_input">
									<input name="${column.column_name}" type="text" id="${column.column_name}" />
								</li>
							</ul>
						</li>					
					</#if>
				</#list>		
						<li class="l-fieldcontainer">
							<ul>
								<li>
									<button type="button" class="btn btn-success btn-xs" onclick="searchGrid()" style="margin-right: 10px;">查询</button>
									<button type="button" class="btn btn-info btn-xs" onclick="clearSearchForm()">清空</button>
								</li>
							</ul>
						</li>				
					</ul>					
				</div>
			</div>
		</form>
	</div>


	<div id="maingrid"></div>
</body>
</html>